function selectOnchang(obj){
 var value = obj.options[obj.selectedIndex].value;
}

function income_expense_class(){
    $.ajax({
      url: "/api/income_expense_class",
      async: false, //请求是否异步，默认为异步，这也是ajax重要特性
      type: "GET",  //请求方式
      success: function(result) {
      	console.log(result);
        result = $.parseJSON(result);
        var data = result.data;
        console.log(data);
        var codeCates = data.split(",");
        str ='<option value="-1">--请选择--</option>';
        for(x in codeCates){
          str+='<option value="'+codeCates[x]+'">'+codeCates[x]+'</option>';
        }
        $("#income_expense_class_id").html(str);
         
      }
    });
  }
   

function show_income_expense_id(){
    $("#income_expense_id").prop("disabled","");//将子类的select解除锁定
    var target = $("#income_expense_class_id option:selected").val();
    $.ajax({
      url: "/api/income_expense_class/"+target,
      //data : {id:target},
      async: false, //请求是否异步，默认为异步，这也是ajax重要特性
      type: "GET",  //请求方式
      success: function(result) {
        //result = $.parseJSON(result);
        var data = result.data;
        var str="";
        for (var i=0;i<data.length;i++){
        	var item = data[i]
        	 str+='<option value="'+item.id+'">'+item.type_name+'</option>';
        }
        $("#income_expense_id").html(str);
      
      }
    });
  }


function show_account_id(user_id){
    $("#account_id").prop("disabled","");//将子类的select解除锁定
    var user_id = user_id
    var target = $("#account_class_id option:selected").val();
    $.ajax({
      url: "/api/account_class/"+user_id+"/"+target,
      //data : {id:target},
      async: false, //请求是否异步，默认为异步，这也是ajax重要特性
      type: "GET",  //请求方式
      success: function(result) {
        //result = $.parseJSON(result);
        var data = result.data;
        var str="";
        for (var i=0;i<data.length;i++){
        	var item = data[i]
        	 str+='<option value="'+item.id+'">'+item.account_name+'</option>';
        }
        $("#account_id").html(str);
      
      }
    });
  }
  


function post_project_index_js(id, project_id, csrf_token) {
    data = {'index_id': id, 'project_id': project_id};
    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/project_index',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            if (result){
                console.log('ok');
        }
        }
        })

 }


function day_index_info_js(year, month, day, project_id, project_name, csrf_token) {
    data = {'year': year, 'month': month, 'day': day, 'project_id': project_id, 'project_name': project_name};

    $.ajax({
        beforeSend: function (xhr, settings){
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        },
        type: 'post',
        url: '/api/day_index_info',
        data: JSON.stringify(data),
        contentType: 'application/json',
        success: function (result) {
            console.log('ok');
            if (result){
                console.log(result);
        }
        }
        })

 }
